import {
  MetahunmanListItem,
  MetahumanListReq,
  MetahumanListRes,
  UpdateMetahumanReq,
  MetahumanStartRes,
  MetahumanStopRes,
  MetahumanCheckRes,
  updateUserFeedbackReq,
  getHistoriesReq,
  getChatInitReq,
  createQuestionGuideReq
} from '@/common/types';
import apiClient from '../apiClient';

export enum ChatApi {
  MetahumanListApi = '/openapi/v1/metahuman',
  StartMetaHumanApi = '/openapi/v1/metahuman/start',
  CheckMetaHumanApi = '/openapi/v1/metahuman/check',
  StopMetahumanApi = '/openapi/v1/metahuman/stop',
  UpdateMetahumanApi = '/openapi/v1/app',
  CheckMetahumanApi = '/openapi/v1/metahuman/check',
  UpdateUserFeedbackApi = '/api/ruigpt/main/conversation/feedback/modifyUserFeedback',
  GetHistoriesApi = '/openapi/v1/getChatLogs',
  // GetHistoriesApi ='/api/ruigpt/main/application/fetchChatLogs',
  ChatInitApi = '/api/ruigpt/main/conversation/init',

  // 获取聊天记录
  ChatRecordsApi = '/openapi/v1/chat/getPaginationRecords',
  // ChatRecordsApi = '/api/core/chat/getPaginationRecords',


  ChatDeleteApi = '/api/ruigpt/main/conversation/item/remove',
  createQuestionGuideApi = '/api/ruigpt/main/ai/agent/buildQuestionGuide',
  UpdateChatApi = '/openapi/v2/sentence_cite/update_chat',
}

const metahumanList = (data: MetahumanListReq) => apiClient.get<MetahumanListRes>({ url: ChatApi.MetahumanListApi, params: data });
const startMetaHuman = (avatarId: string) => apiClient.get<MetahumanStartRes>({ url: ChatApi.StartMetaHumanApi + `/${avatarId}` });
const stopMetahuman = (taskId: string) => apiClient.get<MetahumanStopRes>({ url: ChatApi.StopMetahumanApi + `/${taskId}` });
const updateMetahuman = (id: string, data: UpdateMetahumanReq) => apiClient.put<MetahunmanListItem>({ url: ChatApi.UpdateMetahumanApi + `/${id}`, data });
const checkMetahuman = (id: string) => apiClient.get<MetahumanCheckRes>({ url: ChatApi.CheckMetahumanApi + `/${id}` });
const updateUserFeedback = (data: updateUserFeedbackReq) => apiClient.post({ url: ChatApi.UpdateUserFeedbackApi, data });
const getHistories = (data: getHistoriesReq, signal?: AbortSignal) => apiClient.post({ url: ChatApi.GetHistoriesApi, data, signal });
const chatInitApi = (data: getChatInitReq) => apiClient.get({ url: ChatApi.ChatInitApi, params: data });
const ChatRecords = (data: getChatInitReq) => apiClient.post({ url: ChatApi.ChatRecordsApi, data });
const getCardList = (data: MetahumanListReq) => apiClient.get<MetahumanListRes>({ url: ChatApi.MetahumanListApi, params: data });
const createQuestionGuide = (data: createQuestionGuideReq) => apiClient.post({ url: ChatApi.createQuestionGuideApi, data });

const chatDelete = (contentId: string, chatId: string, appId: string) => apiClient.delete(
  { url: ChatApi.ChatDeleteApi, params: { contentId, chatId, appId } }
);

const updateChat = (data: { chatId: string }) => apiClient.post({ url: ChatApi.UpdateChatApi, data });


export default {
  metahumanList,
  startMetaHuman,
  stopMetahuman,
  updateMetahuman,
  checkMetahuman,
  updateUserFeedback,
  getHistories,
  chatInitApi,
  ChatRecords,
  getCardList,
  chatDelete,
  createQuestionGuide,
  updateChat
};
